{% extends 'iframe/basePlus.html.twig' %}
{% block cardHeader %}
    列表<a href="/Admin/Model/new" class="layui-btn layui-btn-sm" style="float:right;margin-top:6px;">添加</a>
{% endblock %}
{% block cardBody %}
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="gDelete">批量删除</button>
            <button class="layui-btn layui-btn-sm" lay-event="gTableAndFieldManage">表及字段管理</button>
        </div>
    </script>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
    </script>
    <table class="layui-hide" id="list" lay-filter="list"></table>
    <script>
        function getIndexColumn()
        {
            var list = [
                {
                    type: 'radio'
                },
                {
                    title: 'ID',
                    field: 'id',
                    width: ID_WIDTH
                },
                {
                    title: '数据库配置键',
                    field: 'dry_database_config_key'
                },
                {
                    title: '数据库',
                    field: 'dry_database'
                },
                {
                    title: '名称',
                    field: 'dry_name'
                },
                {
                    title: '表名称',
                    field: 'dry_table',
                    width: WIDTH_150
                },
                {
                    title: '别名',
                    field: 'dry_alias',
                    width: WIDTH_150
                },
                {
                    title: '控制器名称',
                    field: 'dry_controller_name',
                    width: WIDTH_150
                },
                {
                    title: '备注',
                    field: 'dry_note'
                },
                {
                    title: '排序',
                    field: 'dry_sort',
                    width: SORT_WIDTH
                },
                {
                    title: '附加字段',
                    field: 'dry_additional_column',
                    templet: function(rs){return mergeRequest("tag", "dry_additional_column", rs.dry_additional_column, "/Api/Choice/getListByKey?key=additionalColumn", "", 1);}
                },
                {
                    title: '分页数',
                    field: 'dry_page_size',
                    templet: function(rs){return mergeRequest("tag", "dry_page_size", rs.dry_page_size, "/Api/Choice/getListByKey?key=pageSize", "", 1);}
                },
                {
                    title: '添加时间',
                    field: 'dry_add_time',
                    width: ADD_TIME_WIDTH
                },
                {
                    title:'操作',
                    toolbar: '#bar',
                    width: OPERATE_WIDTH
                }
            ];
            return list;
        }

        layui.use(['dry', 'jquery', 'layer'], function(dry, $, layer){
            var f = {};

            /*批量删除*/
            f.gDelete = function(object, checkStatus)
            {
                console.log(object);
                console.log(checkStatus);
            };

            f.gTableAndFieldManage = function(object, checkStatus)
            {
                if(!checkStatus.data.length){
                    layer.msg("请选择一个模型后再操作");
                    return false;
                }
                var data = (checkStatus.data)[0];
                layer.open({
                    type: 2,
                    title: '表及字段管理',
                    shadeClose: true,
                    shade: false,
                    maxmin: true,
                    area: ['100%', '100%'],
                    content: '/Admin/Model/field?id=' + data.id
                });
            };

            /*即时编辑*/
            f.immediatelyEdit = function(object)
            {
                console.log(object);
            };

            /*表格渲染结束*/
            f.done = function(response, currentPage, count)
            {
                dry.mergeRequest();
            };

            /*查看按钮*/
            f.show = function(object, id)
            {
                window.location.href = "/Admin/Model/show?id=" + id;
            };

            /*编辑按钮*/
            f.edit = function(object, id)
            {
                window.location.href = "/Admin/Model/edit?id=" + id;
            };

            dry.list("/Api/Model/index", getIndexColumn(), 100, f);
        });
    </script>
{% endblock %}